public class DirectoryTest {

	public void testDirConstructor() {
		// Dir has name and null parent
		Directory d1 = new Directory("dir1", null);
		assert d1.getName().equals("dir1");
		assert d1.getParent() == (null);

		// Dir has name and non-null parent
		Directory d2 = new Directory("dir2", d1);
		assert d2.getName() == "dir2";
		assert d2.getParent() == d1;
		System.out.println("constructor works");
	}

	public void testOriginalContents() {
		// Check if "." and ".." is in Dir contents
		Directory d1 = new Directory("dir1", null);
		assert d1.getContents().containsKey(".");
		assert d1.getContents().containsKey("..");

		// Ensure "." points to itself
		assert d1.getContents().get(".") == d1;

		// Ensure ".." points to itself when parent is null
		assert d1.getContents().get("..") == d1;

		// Ensure ".." points to parent when parent is non-null
		Directory d2 = new Directory("dir2", d1);
		assert d2.getContents().get("..") == d1;
		System.out.println(".. and . opperate as expected");
	}

	public void testAdd() {
		// Add one directory to another directory's contents
		Directory d1 = new Directory("dir1", null);
		Directory d2 = new Directory("dir2", d1);
		d1.addItem("dir2", d2);
		assert d1.getContents().get("dir2") == d2;

		// Add a file to directory
		File f1 = new File("f1", d1);
		d1.addItem("f1", f1);
		assert d1.getContents().get("f1") == f1;

		// Add a directory stored as SystemItem
		SystemItem s1 = new Directory("s1", d1);
		d1.addItem("s1", s1);
		assert d1.getContents().get("s1") == s1;

		// Check Type casting
		Directory test = (Directory) d1.getContents().get("s1");
		assert test == s1;

		// Add a file stored as SystemItem
		s1 = new File("s2", d1);
		d1.addItem("s2", s1);
		assert d1.getContents().get("s2") == s1;

		System.out.println("Items can be added to directory contents");
	}

	public void testRemove() {
		// Remove a directory
		Directory d1 = new Directory("dir1", null);
		Directory d2 = new Directory("dir2", d1);
		d1.addItem("dir2", d2);
		d1.removeItem("dir2");
		assert d1.getContents().get("dir2") == null;

		// Remove a file
		File f1 = new File("f1", d1);
		d1.addItem("f1", f1);
		d1.removeItem("f1");
		assert d1.getContents().get("f1") == null;
		System.out.println("Items can be removed from directory contents");
	}

	public void testPrintContents() {
		// Test Empty Directory
		Directory d1 = new Directory("dir1", null);
		d1.printContents();
		System.out.println("above should be nothing (not even empty line)\n");

		// Test Directory with 1 elements
		Directory d2 = new Directory("dir2", d1);
		d1.addItem("dir2", d2);
		d1.printContents();
		System.out.println("above should be: dir2");

		// Test Directory with 2 elements of multiple types
		File f1 = new File("f1", d1);
		d1.addItem("f1", f1);
		d1.printContents();
		System.out.println("above should be: dir2 f1 (in new lines)");

	}

	public static void main(String[] args) {
		DirectoryTest tester = new DirectoryTest();
		tester.testDirConstructor();
		tester.testOriginalContents();
		tester.testAdd();
		tester.testRemove();
		System.out.println();
		System.out.println("Testing Print Contents now:");
		tester.testPrintContents();
	}
}
